package com.future.direction.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.future.direction.R;
import com.future.direction.common.util.UIUtil;
import com.future.direction.interfaces.OnItemClickListener;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhp on 2019/10/25
 */
public class VipAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private int mPosition = 0;
    private OnItemClickListener onItemClickListener;

    public void setPosition(int position) {
        this.mPosition = position;
    }

    public int getmPosition() {
        return mPosition;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new VipViewHolder(LayoutInflater.from(UIUtil.getContext()).inflate(
                R.layout.item_vip, parent, false));

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (holder instanceof VipViewHolder) {
            VipViewHolder vipViewHolder = (VipViewHolder) holder;

            if (position == mPosition) {
                vipViewHolder.itemView.setBackgroundResource(R.drawable.back_vip_check);
                vipViewHolder.tvTitle.setBackgroundResource(R.drawable.back_vip_text_check);
                vipViewHolder.tvTitle.setTextColor(UIUtil.getColor(R.color.colorWhite));
            } else {
                vipViewHolder.itemView.setBackgroundResource(R.drawable.back_vip_uncheck);
                vipViewHolder.tvTitle.setBackgroundResource(R.drawable.back_vip_text_uncheck);
                vipViewHolder.tvTitle.setTextColor(UIUtil.getColor(R.color.colorBlackA6AEB7));
            }
            vipViewHolder.itemView.setOnClickListener(v -> {
                if (null != onItemClickListener) {
                    onItemClickListener.onItemClick(v, position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return 6;
    }

    public static class VipViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_price)
        TextView tvPrice;

        public VipViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
